package com.bacon.gmall.product.controller;

import com.bacon.gmall.common.result.Result;
import com.bacon.gmall.product.utils.FileUploadUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author： bacon、
 * @version： 1.0
 * @create： 2020-12-21 14:20
 * @description:
 */
@RestController
@RequestMapping("admin/product")
public class FileController {

    @Value("${img.url}")
    private String result;

    //public Result fileUpload(@RequestParam MultipartFile file){ 多张图片
    //单张图片
    @PostMapping("/fileUpload")
    public Result fileUpload(MultipartFile file) {

        System.out.println(file.getName());
        //原始名称
        System.out.println(file.getOriginalFilename());

        String p = FileUploadUtil.fileUpload("fdfs_client.conf", file);
        System.out.println(p);

        if (p != null) {
            return Result.ok(result + p);
        }

        return null;
    }
}
